package com.store.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.store.domain.R;
import com.store.domain.entity.Log;
import com.store.mapper.LogMapper;
import com.store.service.LogService;
import org.springframework.stereotype.Service;

import java.util.Arrays;

/**
 * 日志表(Log)表服务实现类
 *
 * @author yu
 * @since 2024-06-26 01:12:42
 */
@Service("logService")
public class LogServiceImpl extends ServiceImpl<LogMapper, Log> implements LogService {

    @Override
    public void saveLog(Log log) {
        save(log);
    }

    @Override
    public R getLogPage(Integer pageNum, Integer pageSize, String username) {
        LambdaQueryWrapper<Log> queryWrapper = new LambdaQueryWrapper<>();
        if (username != null) {
            queryWrapper.like(Log::getUsername, username);
        }
        Page<Log> page = new Page<>(pageNum, pageSize);
        page(page, queryWrapper);
        return R.success(page.getTotal(), page.getRecords());
    }

    @Override
    public R deleteLog(Integer[] ids) {
        if (removeByIds(Arrays.asList(ids))){
            return R.success("删除成功");
        }
        return R.error("删除失败");
    }
}


